<#assign urlentitys="${rc.contextPath}/codegenerator/codegeneratorAdminJsonEntitys" />
<#assign urlselectentity="${rc.contextPath}/codegenerator/codegeneratorAdminJsonSelectEntity" />
<#assign urltrueOrFalseSelect="${rc.contextPath}/tools/trueOrFalseSelectJson" />
<#assign urlvalidTypes ="${rc.contextPath}/codegenerator/codegeneratorAdminJsonValidTypes" />
<#assign urltextTypes ="${rc.contextPath}/codegenerator/codegeneratorAdminJsonTextTypes" />
<#assign urlsave ="${rc.contextPath}/codegenerator/codegeneratorAdminJsonSave" />
<#assign urlall ="${rc.contextPath}/codegenerator/codegeneratorAdminJsonAll" />
<!--include常量-->
<#include "/misc/backConstant.ftl">
<script type="text/javascript">
		var current = "${currentActionName}";
		function saveCodeGeneratorAll() {
			$.ajax({
				type : "post",
				url : "${urlall}",
				async : false,
				success : function(result) {
					if (result != null) {
						if (result.success) {
							$.messager.alert('成功', "代码生成完成，请到目录查看", 'info');
						} else {
							if (result.msg != null) {
								$.messager.alert('异常提示', result.msg, 'error');
							} else {
								$.messager.alert('异常提示', '提交出现异常，请检查您的输入项，或与管理员联系', 'error');
							}
						}
					}
				}
			});
		}
		function saveCodeGenerator() {
			$("#fm" + current).form("submit", {
				url : "${urlsave}",
				onSubmit : function() {
					var vd = $(this).form("validate");
					return vd;
				},
				success : function(result) {
					result = eval("(" + result + ")");
					if (result != null) {
						if (result.success) {
							$.messager.alert('成功', "代码生成完成，请到目录查看", 'info');
						} else {
							if (result.msg != null) {
								$.messager.alert('异常提示', result.msg, 'error');
							} else {
								$.messager.alert('异常提示', '提交出现异常，请检查您的输入项，或与管理员联系', 'error');
							}
						}
					}
				},
				onLoadError : function(XMLHttpRequest) {
					$.messager.alert('异常提示', XMLHttpRequest.responseText, 'warning');
				}
			});
		}
		//设置下拉列表的值
		$.get("${urlentitys}", function(result) {
			var options = {
				data : result,
				textField:'name',
				valueField:'id',
			};
			$('#className${currentActionName}').combobox(options);
		});
		$('#className${currentActionName}').combobox({
			onSelect: function (record) {
				document.getElementById("codegeneratorfields").style.display='';
				$.get("${urlselectentity}?className=" + record.id, function(result) {
					$('#comment${currentActionName}').textbox("setText", result.comment);
					$('#comment${currentActionName}').textbox("setValue", result.comment);
					$('#packageName${currentActionName}').textbox("setText", result.packageName);
					$('#packageName${currentActionName}').textbox("setValue", result.packageName);
					$('#moduleName${currentActionName}').textbox("setText", result.moduleName);
					$('#moduleName${currentActionName}').textbox("setValue", result.moduleName);
					$('#projectPath${currentActionName}').textbox("setText", result.projectPath);
					$('#projectPath${currentActionName}').textbox("setValue", result.projectPath);
					$('#genCodePath${currentActionName}').textbox("setText", result.genCodePath);
					$('#genCodePath${currentActionName}').textbox("setValue", result.genCodePath);
					$('#genSelect${currentActionName}').combobox('setValue', result.genSelect + "");
					$('#add${currentActionName}').combobox('setValue', result.add + "");
					$('#update${currentActionName}').combobox('setValue', result.update + "");
					$('#detail${currentActionName}').combobox('setValue', result.detail + "");
					$('#delete${currentActionName}').combobox('setValue', result.delete + "");
					$('#search${currentActionName}').combobox('setValue', result.search + "");
					$('#messageInfo${currentActionName}').textbox("setText", result.messageInfo);
					$('#messageInfo${currentActionName}').textbox("setValue", result.messageInfo);
					
					var count = 0;
					$.each(result.codeGeneratorFields, function(name ,value) {
						var trFlag = "<tr bgcolor=\"#FFFFFF\"  height=\"28\"><td><input name=\"codeGeneratorFields[" + count + "].fieldName\" type=\"hidden\" value=\""+value.fieldName+"\">" +value.fieldName + "</td><td><input name=\"codeGeneratorFields[" + count + "].fieldComment\" type=\"hidden\" value=\""+value.fieldComment+"\">" + value.fieldComment + "</td>"
							+ "<td><input name=\"codeGeneratorFields[" + count + "].fieldI18n\" class=\"easyui-textbox\" required=\"true\" style=\"width:220px\" value=\""+value.fieldI18n+"\" /></td>"
							+ "<td><input name=\"codeGeneratorFields[" + count + "].fieldRequired\" class=\"easyui-combobox\" data-options=\"url:'${urltrueOrFalseSelect}?value=" + value.fieldRequired + "',method:'get',valueField:'id',textField:'name'\"  style=\"width:50px\"/></td>"
							+ "<td><input name=\"codeGeneratorFields[" + count + "].validType\" class=\"easyui-combobox\" data-options=\"url:'${urlvalidTypes}?value=" + value.validType + "',method:'get',valueField:'id',textField:'name'\"  style=\"width:60px\" /></td>"
							+ "<td><input name=\"codeGeneratorFields[" + count + "].minLength\" class=\"easyui-numberbox\" required=\"true\" style=\"width:50px\"  value=\""+value.minLength+"\" /></td>"
							+ "<td><input name=\"codeGeneratorFields[" + count + "].maxLength\" class=\"easyui-numberbox\" required=\"true\" style=\"width:50px\"  value=\""+value.maxLength+"\" /></td>"
							+ "<td><input name=\"codeGeneratorFields[" + count + "].fieldType\" class=\"easyui-combobox\" required=\"true\" data-options=\"url:'${urltextTypes}?value=" + value.fieldType + "',method:'get',valueField:'id',textField:'name'\"   style=\"width:90px\"/></td>"
							+ "<td><input name=\"codeGeneratorFields[" + count + "].comboboxUrl\" class=\"easyui-textbox\" style=\"width:160px\"  value=\""+value.comboboxUrl+"\"/></td>"
							+ "<td><input name=\"codeGeneratorFields[" + count + "].viewList\" class=\"easyui-combobox\" data-options=\"url:'${urltrueOrFalseSelect}?value=" + value.viewList + "',method:'get',valueField:'id',textField:'name'\"  style=\"width:50px\"/></td>"
							+ "<td><input name=\"codeGeneratorFields[" + count + "].viewSearch\" class=\"easyui-combobox\" data-options=\"url:'${urltrueOrFalseSelect}?value=" + value.viewSearch + "',method:'get',valueField:'id',textField:'name'\"  style=\"width:50px\"/></td>"
							+ "<td><input name=\"codeGeneratorFields[" + count + "].childProp\" class=\"easyui-textbox\" style=\"width:100px\"  value=\""+value.childProp+"\"/></td>"
							+ "</tr>"
						$('#forCopy').parent().append($(trFlag));
						count++;
					});
					$.parser.parse($('#codegeneratorfields'));
				});
			}
			//onLoadError : function(XMLHttpRequest) {
				//$.messager.alert('异常提示', XMLHttpRequest.responseText, 'warning');
			//}
		});
</script>
<@spring.form id="fm${currentActionName}" modelAttribute="vm" method="post">
<div style="padding:5px;">
	选择实体：<input name="className" id="className${currentActionName}" class="easyui-combobox" style="width:300px;">&nbsp;&nbsp;
	实体说明：<input name="comment" id="comment${currentActionName}" class="easyui-textbox">&nbsp;&nbsp;
	包名：<input name="packageName" id="packageName${currentActionName}" class="easyui-textbox">&nbsp;&nbsp;
	模块名：<input name="moduleName" id="moduleName${currentActionName}" class="easyui-textbox">&nbsp;&nbsp; <br/><br/>
	资源文件存放路径：<input name="messageInfo" id="messageInfo${currentActionName}" class="easyui-textbox" style="width:300px;">&nbsp;&nbsp; 
	代码路径：<input name="genCodePath" id="genCodePath${currentActionName}" class="easyui-textbox" style="width:300px;">&nbsp;&nbsp; <br/><br/>
	生成本类下拉列表：<input name="genSelect" id="genSelect${currentActionName}" class="easyui-combobox" data-options="url:'${urltrueOrFalseSelect}',method:'get',valueField:'id',textField:'name'" style="width:50px;">&nbsp;&nbsp; 
	新增:<input name="add" id="add${currentActionName}" class="easyui-combobox" data-options="url:'${urltrueOrFalseSelect}',method:'get',valueField:'id',textField:'name'" style="width:50px;">&nbsp;&nbsp;
	修改:<input name="update" id="update${currentActionName}" class="easyui-combobox" data-options="url:'${urltrueOrFalseSelect}',method:'get',valueField:'id',textField:'name'" style="width:50px;">&nbsp;&nbsp; 
	详情:<input name="detail" id="detail${currentActionName}" class="easyui-combobox" data-options="url:'${urltrueOrFalseSelect}',method:'get',valueField:'id',textField:'name'" style="width:50px;">&nbsp;&nbsp; 
	搜索:<input name="search" id="search${currentActionName}" class="easyui-combobox" data-options="url:'${urltrueOrFalseSelect}',method:'get',valueField:'id',textField:'name'" style="width:50px;">&nbsp;&nbsp;  
	删除:<input name="delete" id="delete${currentActionName}" class="easyui-combobox" data-options="url:'${urltrueOrFalseSelect}',method:'get',valueField:'id',textField:'name'" style="width:50px;">&nbsp;&nbsp;  
	<br /><br />
	<table id="codegeneratorfields" border="0" cellspacing="1" cellpadding="0" bgcolor="#87CEFA" style="width:100%;height:auto;display:none;">
		<tr id="forCopy" bgcolor="#FFFFFF" height="28">
			<td>名称</th>
			<td>描述</th>
			<td>国际化</th>
			<td>是否必填</th>
			<td>验证类型</th>
			<td>最小长度</th>
			<td>最大长度</th>
			<td>文本框类型</th>
			<td>选择来源</th>
			<td>列表显示</th>
			<td>搜索显示</th>
			<td>二级属性</th>
		</tr>
	</table>
</div>
<a href="#" onclick="saveCodeGenerator()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">开始生成代码</a>&nbsp;&nbsp;  &nbsp;&nbsp;  
<a href="#" onclick="saveCodeGeneratorAll()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">生成所有代码</a>
</@spring.form>